<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Inc. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/documents
 */
class appmanualController extends appRain_Base_Core
{
    public $name = 'appManual';

    /**
     * This function will reander the home page
     *
     * @return null
     */
    public function indexAction($action=null,$id=NULL)
    {
        $this->addons = array('syntaxhighlighter','defaultvalues','addthis');
		$this->pageNameToMetaInfo('Manual');

        $categoryData = Array();
        $page_content = $this->PageManager()
                             ->getData( "Manual");

		$cid = "";
		$scid = "";
        //-- If the request to view category
        if($action == 'c')
        {
            $categoryData = $this->CategorySet("manual-cat")
								 ->findById($id);
			$this->page_title = $categoryData['title'] . ' | appRain CMS and Framework Manual';
            $allPost = $this->InformationSet("manual-post")->findAll("1 ORDER BY generic ASC",Array(Array("category" => "{$id}")));
            $this->set('allPost',$allPost);

            $cid = ($categoryData['parent_id']!=0) ? $categoryData['parent_id'] : $id;
			$scid = $id;
        }
        //-- If the request to view post
        else if ($action == 'p')
        {
			$this->addons[] = 'simple_menu';
            $post = $this->InformationSet("manual-post")->findById($id);
			$this->page_title = $post['title'] . ' | appRain CMS and Framework Help';
            $this->set('post',$post);

            $categoryData = $this->CategorySet("manual-cat")
                                 ->findById($post['category']);

			$cid = ($categoryData['parent_id']!=0) ? $categoryData['parent_id'] : $post['category'];
			$scid = $post['category'];
        }

        $categories = $this->CategorySet("manual-cat")
                           ->findAll("parent_id=0 ORDER BY generic ASC");

        //--- Set Data in Tempalte ---
        $this->set("section_title","Manual");
        $this->set("action",$action);
        $this->set("selected","manual");
        $this->set("id",$id);
        $this->set("cid",$cid);
		$this->set("scid",$scid);
        $this->set("categories",$categories);
        $this->set("categoryData",$categoryData);
        $this->set("page_content",$page_content);
    }
}
